package com.example.springboot_template.exception;


import com.example.springboot_template.common.BaseResponse;
import com.example.springboot_template.common.ErrorCode;
import com.example.springboot_template.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        log.error("BusinessException:" +  e.getMessage(),e);
        return ResultUtils.error(e.getCode(),e.getMessage(),e.getDescription());
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
        log.error("RuntimeException:" +  e);
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR,e.getMessage());
    }

}
